package com.huawei.appgallery.purchasehistory.ui.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.CompoundButton;
import android.widget.CompoundButton.OnCheckedChangeListener;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.TextView;
import androidx.annotation.Nullable;
import com.huawei.appgallery.purchasehistory.ui.bean.AppInfo;
import com.huawei.appmarket.framework.widget.NoAdaptRenderImageView;
import huawei.widget.HwSwitch;
import java.util.List;
import o.azb;
import o.cst.d;
import o.dof;
import o.eqx;

public class FamilyShareAppListAdapter extends BaseAdapter {
    private List<AppInfo> mDatas;
    private LayoutInflater mInflater;
    private a mOnItemCheckedChangeListener;

    public interface a {
        void b_(int i);
    }

    static class e {
        View ʻ;
        ImageView ˊ;
        NoAdaptRenderImageView ˋ;
        TextView ˎ;
        TextView ˏ;
        HwSwitch ॱ;

        private e() {
        }
    }

    public FamilyShareAppListAdapter(Context context, List<AppInfo> list) {
        this.mDatas = list;
        this.mInflater = LayoutInflater.from(context);
    }

    public int getCount() {
        return this.mDatas.size();
    }

    public Object getItem(int i) {
        return this.mDatas.get(i);
    }

    public long getItemId(int i) {
        return (long) i;
    }

    public View getView(int i, View view, ViewGroup viewGroup) {
        e eVar;
        if (view != null) {
            eVar = (e) view.getTag();
        } else {
            view = this.mInflater.inflate(d.ʽ, null);
            eVar = new e();
            initViewHolder(eVar, view);
            view.setTag(eVar);
        }
        setData(eVar, i);
        return view;
    }

    private void setData(e eVar, final int i) {
        AppInfo appInfo = (AppInfo) this.mDatas.get(i);
        if (appInfo.ʼ() != 0) {
            String ˎ = appInfo.ˎ();
            if (dof.ˋ(ˎ)) {
                eVar.ˋ.setVisibility(8);
            } else {
                eVar.ˋ.setVisibility(0);
                eqx.ˎ(eVar.ˋ, ˎ);
            }
            CharSequence ʽ = appInfo.ʽ();
            if (dof.ˋ(ʽ)) {
                eVar.ˎ.setVisibility(8);
            } else {
                eVar.ˎ.setVisibility(0);
                eVar.ˎ.setText(ʽ);
            }
        } else {
            eVar.ˋ.setVisibility(8);
            eVar.ˎ.setVisibility(8);
        }
        if (eVar.ˊ != null) {
            eqx.ˏ(eVar.ˊ, appInfo.ˊ(), "defaultPresetResourceKey");
        }
        if (eVar.ˏ != null) {
            eVar.ˏ.setText(appInfo.ॱ());
        }
        if (eVar.ॱ != null) {
            eVar.ॱ.setOnCheckedChangeListener(null);
            eVar.ॱ.setChecked(1 == appInfo.ˋ());
            eVar.ॱ.setOnCheckedChangeListener(new OnCheckedChangeListener(this) {
                final /* synthetic */ FamilyShareAppListAdapter ˋ;

                public void onCheckedChanged(CompoundButton compoundButton, boolean z) {
                    this.ˋ.mOnItemCheckedChangeListener.b_(i);
                }
            });
        }
        if (i == this.mDatas.size() - 1) {
            eVar.ʻ.setVisibility(8);
        } else {
            eVar.ʻ.setVisibility(0);
        }
    }

    private void initViewHolder(e eVar, View view) {
        eVar.ˊ = (ImageView) view.findViewById(o.cst.e.ʻ);
        azb.ॱ(eVar.ˊ);
        eVar.ˏ = (TextView) view.findViewById(o.cst.e.ˏ);
        eVar.ʻ = view.findViewById(o.cst.e.ʿ);
        azb.ʻ(eVar.ʻ);
        eVar.ॱ = (HwSwitch) view.findViewById(o.cst.e.ˉ);
        azb.ʻ(eVar.ॱ);
        eVar.ˋ = (NoAdaptRenderImageView) view.findViewById(o.cst.e.ˋᐝ);
        eVar.ˎ = (TextView) view.findViewById(o.cst.e.ᐨ);
    }

    public void setOnItemCheckedChangeListener(@Nullable a aVar) {
        this.mOnItemCheckedChangeListener = aVar;
    }

    public void updateItemView(ListView listView, int i) {
        int firstVisiblePosition = i - listView.getFirstVisiblePosition();
        if (firstVisiblePosition >= 0 && firstVisiblePosition < listView.getChildCount()) {
            getView(i, listView.getChildAt(firstVisiblePosition), listView);
        }
    }
}
